#include <stdio.h>

//fgets与fputs实现文件加密解密
//加密
//遍历字符串，然后再++
void decode(char *s)
{
    int len = 0;
    while(s[len])
    {
        s[len]++;
        len++;
    }
}

//解密
//遍历字符串，然后再--
void encode(char *s)
{
    int len = 0;
    while(s[len])
    {
        s[len]--;
        len++;
    }
}

int main(int argc, char **args)
{
    if(argc < 4)
        return 0;

    FILE *p1 = fopen(args[1], "r");
    if (p1 == NULL)
        return 0;

    FILE *p2 = fopen(args[2], "w");
    if (p2 == NULL)
        return 0;

    while(!feof(p1))
    {
        char buf[1024] = { 0 };
        fgets(buf, sizeof(buf), p1);

        if (args[3][0] == '0')
            decode(buf);
        else
            encode(buf);

        fputs(buf, p2);
    }
    fclose(p1);
    fclose(p2);

    return 0;
}

